package com.sicent.operate.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.sicent.upms.operate.data.UserData;

@Controller
@RequestMapping("admin/user")
public class LoginController {

	@Autowired
	private UserData userData;
	
	@RequestMapping(value="login",method=RequestMethod.POST)
	public String userLogin(String userName,String userPassword,
			HttpServletResponse response,
			HttpServletRequest request,Model model){
		try {
			if(StringUtils.isBlank(userName)||StringUtils.isBlank(userPassword)){
				throw new RuntimeException("用户名密码为空");
			}
			userData.userLogin(userName, userPassword,request,response);
			return "index/index";
		} catch (Exception e) {
			model.addAttribute("msg", e.getMessage());
			return "user/login";
		}
	}
}
